package com.bwie.controller;

import com.bwie.pojo.TbProd;
import com.bwie.pojo.TbProdAtta;
import com.bwie.service.TbProdService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 牛毅
 * @version 1.0
 * @date 2025/7/19
 * @description TODO
 */
@RestController
@RequestMapping("/prod/index")
public class ProdController {
    @Autowired
    TbProdService tbProdService;

    /** 
     * @description: 获取商品列表 
     * @param: pageInfoVo 
     * @return: com.bwie.utils.R 
     * @author 牛毅
     * @date: 2025/7/21 16:15
     */ 
    @PostMapping("/getProdList")
    public R getProdList(@RequestBody PageInfoVo pageInfoVo){
        return tbProdService.getProdList(pageInfoVo);
    }

    /**
     * @description: 批量删除商品
     * @param: null
     * @return:
     * @author 牛毅
     * @date: 2025/7/22 9:48
     */
    @PostMapping("/deleteByIds")
    public R deleteByIds(@RequestBody List<TbProd> ids){
        return tbProdService.deleteByIds(ids);
    }    /**
     * @description: 添加商品
     * @param: null
     * @return:
     * @author 牛毅
     * @date: 2025/7/22 9:48
     */
    @PostMapping("/addProd")
    public R addProd(@RequestBody @Validated TbProd tbProd, BindingResult result){
        return tbProdService.addProd(tbProd,result);
    }

    @PostMapping("/addProdAtta")
    public R addProdAtta(@RequestBody TbProdAtta tbProdAtta){
        return tbProdService.addProdAtta(tbProdAtta);
    }

    @PostMapping("/getProdDetail")
    public R getProdDetail(@PathVariable("prodId") Integer prodId){
        return tbProdService.getProdDetail(prodId);
    }
}
